{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Python 循环"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* while循环[循环体的范围通过缩进表示循环体]\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n",
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "6\n",
      "7\n",
      "8\n",
      "9\n",
      "++++++++++\n",
      "10\n"
     ]
    }
   ],
   "source": [
    "temp=0\n",
    "while temp<10:\n",
    "    print(temp)\n",
    "    temp += 1\n",
    "\n",
    "print('++++++++++')\n",
    "print(temp)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### list和set集合的遍历\n",
    "* while list/set ：集合如果为null就跳出循环\n",
    "* for item in list/set: 这种模式进行遍历"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [],
   "source": [
    "temp=list([1,2,3,4,5])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5\n",
      "4\n",
      "3\n",
      "2\n",
      "1\n",
      "++++++++++\n",
      "[]\n"
     ]
    }
   ],
   "source": [
    "while temp :\n",
    "    t=temp.pop()\n",
    "    print(t)\n",
    "print('++++++++++')\n",
    "print(temp)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n",
      "4\n",
      "5\n",
      "++++++++++++++\n",
      "{1, 2, 3, 4, 5}\n",
      "5\n"
     ]
    }
   ],
   "source": [
    "temp=set([1,2,3,4,5])\n",
    "for item in temp:\n",
    "    print(item)\n",
    "print(\"++++++++++++++\")\n",
    "print(temp)\n",
    "print(item)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* for循环中使用range()指定循环范围,遍历变成index"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "temp = [123,435,1234,513245,11243,1234,1234,534,346]"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "123\n",
      "435\n",
      "1234\n",
      "513245\n",
      "11243\n",
      "1234\n",
      "1234\n",
      "534\n",
      "346\n",
      "++++++++++++++\n",
      "8\n"
     ]
    }
   ],
   "source": [
    "for i in range(len(temp)) :\n",
    "    print(temp[i])\n",
    "print('++++++++++++++')\n",
    "print(i)\n",
    "    "
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "* 循环、if 、break ,continue 混用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "10\n",
      "12\n",
      "12\n",
      "14\n",
      "14\n",
      "+++++++++++\n"
     ]
    }
   ],
   "source": [
    "temp = [10,11,12,13,14,15]\n",
    "for item in temp :\n",
    "    if item%2==0 :\n",
    "        print(item)\n",
    "    else :\n",
    "        continue\n",
    "    print(item)\n",
    "print('+++++++++++')        \n",
    "        \n",
    "        "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "10\n",
      "10\n",
      "+++++++++++\n"
     ]
    }
   ],
   "source": [
    "temp = [10,11,12,13,14,15]\n",
    "for item in temp :\n",
    "    if item%2==0 :\n",
    "        print(item)\n",
    "    else :\n",
    "        break\n",
    "    print(item)\n",
    "print('+++++++++++')  "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
